package com.guoyh.baseutils

import android.app.Application
import android.view.Gravity
import com.getkeepsafe.relinker.ReLinker
import com.hjq.toast.ToastUtils
import com.hjq.toast.style.BlackToastStyle
import com.tencent.mmkv.MMKV
import com.xuexiang.xui.XUI
import com.guoyh.baseutils.ext.dp2px
import com.guoyh.baseutils.utils.NotifyUtils

/**
 * @CreateDate: 7/14/21 3:43 PM
 * @Author: guoyh
 * @Description:
 */
object InitCommonUtils {

    fun initCommonUtils(application: Application) {
        XUI.init(application)
        initToast(application)
        initMMKV(application)
        initThrowe(application)
        //通知栏初始化
        NotifyUtils.setNotificationChannel(application);
    }

    private fun initThrowe(application: Application) {
//        CaocConfig.Builder.create()
//            .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
//            .enabled(true) //default: true
//            .showErrorDetails(false) //default: true
//            .showRestartButton(true) //default: true
//            .logErrorOnRestart(false) //default: true
//            .trackActivities(true) //default: false
//            .minTimeBetweenCrashesMs(2000) //default: 3000
//            .errorDrawable(R.drawable.ic_custom_drawable) //default: bug image
//            .restartActivity(SplashActivity::class.java) //default: null (your app's launch activity)
//            .errorActivity(ErrorActivity::class.java) //default: null (default error activity)
//            .apply()
    }

    private fun initToast(application: Application) {
        ToastUtils.init(application, BlackToastStyle())
        ToastUtils.setGravity(Gravity.BOTTOM, 0, dp2px(100F, application))
    }

    private fun initMMKV(application: Application) {
        val dir: String = application.filesDir.absolutePath.toString() + "/mmkv"
        MMKV.initialize(application, dir) { libName ->
            ReLinker.loadLibrary(application, libName)
        }
    }


}